﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace PlasmaMes
{
    public partial class Form_Rfid: Form
    {
        Dictionary<UIButton, Form> m_dicForm = new Dictionary<UIButton, Form>();
        public Form_Rfid()
        {
            InitializeComponent();

            m_dicForm.Add(bt_连接, new Form_Rfid_Connect());
            m_dicForm.Add(bt_测试, new Form_Rfid_Test());
            
        }

        private void Form_Rfid_Load(object sender, EventArgs e)
        {
            foreach (var kp in m_dicForm)
            {
                kp.Value.TopLevel = false;
                kp.Value.Parent = this.panel_Rfid;
                kp.Value.AutoScroll = true;
                kp.Value.Dock = DockStyle.Fill;
            }

            bt_连接.PerformClick();
        }

        private void FormDisplay(UIButton uiSymbolButton)
        {
            this.Invoke(new Action(() =>
            {
                uiSymbolButton.FillColor = Color.FromArgb(0, 192, 0);
                uiSymbolButton.FillHoverColor = Color.FromArgb(0, 192, 0);
                uiSymbolButton.FillPressColor = Color.FromArgb(0, 192, 0);
                panel_Rfid.Controls.Clear();
                panel_Rfid.Controls.Add(m_dicForm[uiSymbolButton]);
                m_dicForm[uiSymbolButton].Show();
            }));

            foreach (var btn in m_dicForm.Keys)
            {
                if (btn != uiSymbolButton)
                {
                    this.Invoke(new Action(() =>
                    {
                        btn.FillColor = Color.FromArgb(80, 160, 255);
                        btn.FillHoverColor = Color.FromArgb(80, 160, 255);
                        btn.FillPressColor = Color.FromArgb(80, 160, 255);
                    }));
                }
            }
        }

        private void bt_连接_Click(object sender, EventArgs e)
        {
            FormDisplay(bt_连接);
        }

        private void bt_测试_Click(object sender, EventArgs e)
        {
            FormDisplay(bt_测试);
        }
    }
}
